#include "check_dialog.h"
#include "ui_check_dialog.h"
#include<QString>
#include<QDebug>
#include<QMessageBox>
#include"qualifydocu.h"
#include"sqlconnect.h"
check_dialog::check_dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::check_dialog)
{
    ui->setupUi(this);
    connect(ui->cancel,SIGNAL(clicked(bool)),this,SLOT(close()));
    connect(ui->confirm,SIGNAL(clicked(bool)),this,SLOT(react()));
    connect(ui->confirm,SIGNAL(clicked(bool)),parent,SLOT(showCheckInfo()));
}
check_dialog::~check_dialog()
{
    delete ui;
}

void check_dialog::react(){
    QString year=ui->checkYear->date().toString();
    QString result=ui->checkResult->currentText();
    year=year.right(4);
    //qDebug()<<year<<" "<<result;
    //sqlconnect(db);
    QSqlQuery qu("select * from  `Check` where CheckYear='"+year+"' and IDNum='"+ID+"'");
    if(qu.next())
    {
        QMessageBox::information(this,"提示信息","该年度考核已存在，不可重复添加！");
        return;
    }


    QSqlQuery query;
    QString sql="INSERT INTO `Check`(CheckYear,CheckResult,IDNum)VALUES('"+year+"','"+result+"','"+ID+"')";
    bool ok=query.exec(sql);
    qDebug()<<ok;
    if(ok){
        QMessageBox::information(this,"提示信息","考核成功插入!");
    }

    //db.close();
    this->close();
}

void check_dialog::reciveID(QString s){
    ID=s;
}
